let format = n => {
    let num = n.toString()
    let decimals = ''
        // 判断是否有小数
    num.indexOf('.') > -1 ? decimals = num.split('.')[1] : decimals
    let len = num.length
    if (len <= 3) {
        return num
    } else {
        let temp = ''
        let remainder = len % 3
        decimals ? temp = '.' + decimals : temp
        if (remainder > 0) { // 不是3的整数倍
            return num.slice(0, remainder) + ',' + num.slice(remainder, len).match(/\d{3}/g).join(',') + temp
        } else { // 是3的整数倍
            return num.slice(0, len).match(/\d{3}/g).join(',') + temp
        }
    }
}
$(


    function() {

        // 数据准备
        var chart_data = []
        Object.keys(data).forEach(state => {
            chart_data.push({
                stateName: state,
                totalCases: data[state]['2020/05/19']['cumsum_confirmed'],
                totalDeath: data[state]['2020/05/19']['cumsum_death'],
                deathRate: data[state]['2020/05/19']['death_ratio']
            })
        })

        var curRow = 0;
        $('#sum_table').bootstrapTable('destroy').bootstrapTable({
            // showRefresh: true,

            clickToSelect: true,
            columns: [{
                field: 'stateName',
                title: 'State Name',
                //     formatter: function (value, row, index) {
                //        return index+1;
                //    },
                halign: 'center',
                align: 'center',
                sortable: true
            }, {
                field: 'totalCases',
                title: 'Total Cases',
                halign: 'center', //表头居中显示
                align: 'right',
                sortable: true,
                formatter: function(value, row, index) {
                    return format(value)
                }

            }, {
                field: 'totalDeath',
                title: 'Total Death',
                halign: 'center',
                align: 'right',
                sortable: true,
                formatter: function(value, row, index) {
                    return format(value)
                }
            }, {
                field: 'deathRate',
                title: 'Death Rate',
                halign: 'center',
                align: 'right',
                sortable: true,
                formatter: function(value, row, index) {
                    return (value * 100).toFixed(4) + "%"
                },
            }],

            // pagination: true, //设置为 true 会在表格底部显示分页条。
            // paginationLoop: false, //设置为 true 启用分页条无限循环的功能。
            // pageSize: 10, //每页初始显示的条数
            // pageList: [10, 15, 20],
            // toolbar: '#toolbar', //工具栏
            // toolbarAlign: 'right', //工具栏的位置
            // stickyHeader: true,
            //fixedNumber: 1, //固定列数   
            data: chart_data,
            //[{ stateName: 'adsad', totalCases: 100, totalDeath: 100, deathRate: 0.1 }],

            onClickRow: function(row, $element) {
                curRow = row
                console.log(row)
            },
            onPageChange: function() {

            }

        });






    }



)